package com.fadada.api;

import com.fasc.open.api.bean.base.BaseRes;
import com.fasc.open.api.bean.req.corpmanage.GetManageUrlReq;
import com.fasc.open.api.bean.req.corpmanage.GetTemplateUrlReq;
import com.fasc.open.api.bean.res.common.EUrlRes;
import com.fasc.open.api.bean.res.common.PUrlRes;
import com.fasc.open.api.client.CorpManageClient;
import com.fasc.open.api.enums.corpmanage.ResourceTypeEnum;
import com.fasc.open.api.exception.ApiException;
import com.fasc.open.api.utils.ResultUtil;
import com.fasc.open.api.utils.crypt.FddCryptUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * @author FDD
 * @version 0.0.1
 * @Description 印章管理的demo
 * @Param
 * @createTime 2021/12/20 14:03
 */
public class CorpManageDemo extends BaseDemo{

    private static CorpManageClient corpManageClient;

    public static void main(String[] args) {
        try{
            BaseDemo baseDemo = new BaseDemo();
            openApiClient = baseDemo.getClient();
            corpManageClient = new CorpManageClient(openApiClient);
            //获取应用accessToken
            accessToken = baseDemo.getAccessToken(openApiClient);
            //获取印章管理链接
            getSealUrl();
            //获取模板管理链接
            getTemplateUrl();
        }catch (ApiException e){
            e.printStackTrace();
        }
    }
    public static void getSealUrl() throws ApiException{
        GetManageUrlReq getManageUrlReq = new GetManageUrlReq();
        getManageUrlReq.setAccessToken(accessToken);
        getManageUrlReq.setOpenCorpId(openCorpId);
        getManageUrlReq.setOperatorId(openUserId);
        getManageUrlReq.setResourceId(ResourceTypeEnum.SEAL.getCode());
        getManageUrlReq.setRedirectUrl("http://www.baidu.com");
        BaseRes<EUrlRes> res = corpManageClient.getManageUrl(getManageUrlReq);
        ResultUtil.printLog(res, openApiClient.getJsonStrategy());
    }

    public static void getTemplateUrl() throws ApiException{
        GetTemplateUrlReq getTemplateUrlReq = new GetTemplateUrlReq();
        getTemplateUrlReq.setAccessToken(accessToken);
        getTemplateUrlReq.setOpenCorpId(openCorpId);
        getTemplateUrlReq.setRedirectUrl("http://www.baidu.com");
        BaseRes<PUrlRes> res = corpManageClient.getTemplateUrl(getTemplateUrlReq);
        ResultUtil.printLog(res, openApiClient.getJsonStrategy());
    }

}
